<script>
import { wxLogin } from "./api";
import { wxToLogin } from "@/utils/tools";

// function wxToLogin() {
//   let oUrl = window.location.href;
//   const redirect_uri = encodeURIComponent(oUrl); // API_URL + "";
//   const appid = "wx2e2c0a6dd7555b8c";
//   window.location = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;

//   throw "stop";
// }
// 截取url中的code方法
function getUrlCode() {
  const url = location.search;
  const theRequest = new Object();
  if (url.indexOf("?") != -1) {
    const str = url.substr(1);
    const strs = str.split("&");
    for (let i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
    }
  }
  return theRequest;
}

export default {
  onLaunch: function () {
    console.warn(
      "当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！"
    );
    console.log("App Launch");
  },
  onShow: function () {
    console.log("App Show");
    const token = uni.getStorageSync("token");
    if (!token) {
      const params = getUrlCode();
      if (params.code) {
        console.log("参数", params);
        wxLogin({
          jsCode: params.code,
        }).then((res) => {
          console.log(res);
          uni.setStorageSync("userInfo", res.data);
          uni.setStorageSync("token", res.data.sessionKey);
          // uni.redirectTo({
          // 	url: ''
          // });
        });
      } else {
        wxToLogin();
      }
    }
  },
  onHide: function () {
    console.log("App Hide");
  },
};
</script>

<style lang="scss">
/*每个页面公共css */
@import "uview-ui/index.scss";
.flex-col {
  display: flex;
  flex-direction: column;
}
.flex-row {
  display: flex;
  flex-direction: row;
}

.x-f {
  display: flex;
  align-items: center;
  justify-content: center;
}
.flex-1 {
  flex: 1;
}
.text-hidden {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
uni-page-head .uni-page-head{
  position: absolute!important;
}
uni-app {
  background: url("./static/images/bg1.png") 100% no-repeat;
  background-size: cover;
}
uni-page {
  background: url("./static/images/bg2.png") 100% no-repeat;
  background-size: cover;
}
.pages-support-preSales {
  uni-app {
    background: url("./static/images/bg5.png") 100% no-repeat;
    background-size: cover;
  }
  uni-page {
    background: url("./static/images/bg6.png") 100% no-repeat;
    background-size: cover;
  }
}
.pages-support-afterSale {
  uni-app {
    background: url("./static/images/bg3.png") 100% no-repeat;
    background-size: cover;
  }
  uni-page {
    background: url("./static/images/bg4.png") 100% no-repeat;
    background-size: cover;
  }
}
.pages-support-addedValue,
.pages-support-addedValueInfo,
.pages-support-downLoad {
  uni-app {
    background: url("./static/images/bg7.png") 100% no-repeat;
    background-size: cover;
  }
  uni-page {
    background: url("./static/images/bg8.png") 100% no-repeat;
    background-size: cover;
  }
}
.pages-support-repair {
  uni-app {
    background: url("./static/images/bg5.png") 100% no-repeat;
    background-size: cover;
  }
  uni-page {
    background: url("./static/images/bg10.png") 100% no-repeat;
    background-size: cover;
  }
}
page {
  width: 100%;
  height: 100%;
  // filter: opacity(0.935);
}
.page-box {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  .page-bg {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    // background: url("./static/images/bg1.png") 100% no-repeat;
    // background-size: cover;
  }
  .page-container {
    // background: url("./static/images/bg2.png") 100% no-repeat;
    // background-size: cover;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    z-index: 3;
    .scroll-box {
      height: 100%;
      width: 100%;
      position: relative;
      color: #fff;
      flex: 1;
    }
  }

  .v-form {
    margin: 0 28rpx;
  }
  ::v-deep {
    .u-form-item--left__content__label {
      color: #fff;
    }
    .uni-input-input {
      color: #fff;
    }
    .u-border-bottom:after {
      border-bottom: 1rpx solid #545454;
    }
    .u-input__textarea {
      color: #fff !important;
    }
  }
}
.hide-1row {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  // display: -webkit-box;
  // -webkit-line-clamp: 1;
  // -webkit-box-orient: vertical;
}
.hide-2row {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
</style>
